package zust.se.delicious.action;

import java.util.Map;

import zust.se.delicious.service.BookmarkService;
import zust.se.delicious.vo.BookmarkBean;
import zust.se.delicious.vo.SessionUserBean;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class AddLinkAction extends ActionSupport {
	private boolean success;
	private BookmarkBean bookmark;

	public BookmarkBean getBookmark() {
		return bookmark;
	}

	public String getFormUrl() {
		return "saveLink";
	}

	private BookmarkService bookmarkService;
	private String linkUrl;

	public void setBookmark(BookmarkBean bookmark) {
		this.bookmark = bookmark;
	}

	public void setBookmarkService(BookmarkService bookmarkService) {
		this.bookmarkService = bookmarkService;
	}

	public String getLinkUrl() {
		return linkUrl;
	}

	public void setLinkUrl(String linkUrl) {
		this.linkUrl = linkUrl;
	}

	public boolean getSuccess() {
		return success;
	}

	public String initLinkForm() {
		return SUCCESS;
	}

	public String saveLink() {
		Map session = ActionContext.getContext().getSession();
		SessionUserBean sessionUser = (SessionUserBean) session.get("sessionUser");
		int uid;
		if (sessionUser != null) {
			uid=sessionUser.getId();
			bookmark.setUser_id(uid);
			success=bookmarkService.saveBookmark(bookmark);
		}
		return SUCCESS;
	}
}